<?php
declare (strict_types = 1);

namespace app\cms\middleware;

use Closure;
use http\Client\Response;
use think\Request;

class Cors
{
    /**
     * 处理请求
     *
     * @param Request $request
     * @param Closure       $next
     * @return Response
     */
    public function handle($request, Closure $next)
    {
        $response = $next($request);
        $response->header([
            'Access-Control-Allow-Origin' => '*',
            'Access-Control-Allow-Methods' => 'GET,POST,PUT,DELETE,OPTIONS',
            'Access-Control-Allow-Headers' => 'Origin, X-Requested-With, Content-Type, Accept',
        ]);
        return $response;
    }
}
